package com.ruoyi.sys.safetytraining.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.safetytraining.domain.TbSafetyTraining;
import com.ruoyi.sys.safetytraining.service.ITbSafetyTrainingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训学习Controller
 * 
 * @author iuxin
 * @date 2022-05-25
 */
@RestController
@RequestMapping("/safetyTraining/training")
public class TbSafetyTrainingController extends BaseController
{
    @Autowired
    private ITbSafetyTrainingService tbSafetyTrainingService;

    /**
     * 查询培训学习列表
     */
    @PreAuthorize("@ss.hasPermi('safetyTraining:training:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbSafetyTraining tbSafetyTraining)
    {
        startPage();
        List<TbSafetyTraining> list = tbSafetyTrainingService.selectTbSafetyTrainingList(tbSafetyTraining);
        return getDataTable(list);
    }

    /**
     * 导出培训学习列表
     */
    @PreAuthorize("@ss.hasPermi('safetyTraining:training:export')")
    @Log(title = "培训学习", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbSafetyTraining tbSafetyTraining)
    {
        List<TbSafetyTraining> list = tbSafetyTrainingService.selectTbSafetyTrainingList(tbSafetyTraining);
        ExcelUtil<TbSafetyTraining> util = new ExcelUtil<TbSafetyTraining>(TbSafetyTraining.class);
        util.exportExcel(response, list, "培训学习数据");
    }

    /**
     * 获取培训学习详细信息
     */
    @PreAuthorize("@ss.hasPermi('safetyTraining:training:query')")
    @GetMapping(value = "/{stId}")
    public AjaxResult getInfo(@PathVariable("stId") Long stId)
    {
        return AjaxResult.success(tbSafetyTrainingService.selectTbSafetyTrainingByStId(stId));
    }

    /**
     * 新增培训学习
     */
    @PreAuthorize("@ss.hasPermi('safetyTraining:training:add')")
    @Log(title = "培训学习", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbSafetyTraining tbSafetyTraining)
    {
        return toAjax(tbSafetyTrainingService.insertTbSafetyTraining(tbSafetyTraining));
    }

    /**
     * 修改培训学习
     */
    @PreAuthorize("@ss.hasPermi('safetyTraining:training:edit')")
    @Log(title = "培训学习", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbSafetyTraining tbSafetyTraining)
    {
        return toAjax(tbSafetyTrainingService.updateTbSafetyTraining(tbSafetyTraining));
    }

    /**
     * 删除培训学习
     */
    @PreAuthorize("@ss.hasPermi('safetyTraining:training:remove')")
    @Log(title = "培训学习", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stIds}")
    public AjaxResult remove(@PathVariable Long[] stIds)
    {
        return toAjax(tbSafetyTrainingService.deleteTbSafetyTrainingByStIds(stIds));
    }
}
